using System.Collections.Generic;
using System.Xml;
using BasecampRestAPI;

namespace TestBasecampRestAPI.TestMoveToDoList
{
	public class FakeRestWebService : IRestWebService
	{
		public static FakeRestWebService GetInstance()
		{
			return new FakeRestWebService();
		}

		protected FakeRestWebService()
		{
		}

		public string Url { get; private set; }
		public string UserName { get; private set; }

		public XmlElement GetRequestResponseElement(string requestPath)
		{
			return GetRequestResponseElement(requestPath, string.Empty);
		}

		public XmlElement GetRequestResponseElement(string requestPath, string data)
		{
			return GetRequestResponseElement(requestPath, data, HttpVerb.Get);
		}

		public XmlElement GetRequestResponseElement(string requestPath, string data, HttpVerb verb)
		{
			GetRequestResponseElementCalled = true;
			GetRequestResponseRequestElementPaths.Add(requestPath);
			GetRequestResponseRequestElementData.Add(data);
			GetRequestResponseElementLastRequestPath = requestPath;
			GetRequestResponseElementLastData = data;
			GetRequestResponseElementLastVerb = verb;
			if (GetRequestResponseElementFakeResults.ContainsKey(requestPath))
			{
				return GetRequestResponseElementFakeResults[requestPath];
			}
			return GetRequestResponseElementFakeResult;
		}

		public bool GetRequestResponseElementCalled { get; private set; }
		public string GetRequestResponseElementLastRequestPath { get; private set; }
		public string GetRequestResponseElementLastData { get; private set; }
		public HttpVerb GetRequestResponseElementLastVerb { get; private set; }
		public XmlElement GetRequestResponseElementFakeResult { private get; set; }
		private readonly List<string> GetRequestResponseRequestElementPaths = new List<string>();
		private readonly List<string> GetRequestResponseRequestElementData = new List<string>();
		private readonly Dictionary<string, XmlElement> GetRequestResponseElementFakeResults
			= new Dictionary<string, XmlElement>();
		public void ConfigureRequestResponseElementForPath(string requestPath, XmlElement element)
		{
			GetRequestResponseElementFakeResults[requestPath] = element;
		}
		public bool GetRequestResponseElementCalledForPath(string path)
		{
			return GetRequestResponseRequestElementPaths.Contains(path);
		}

		public string PostRequestGetLocation(string requestPath, string data)
		{
			PostRequestGetLocationCalled = true;
			PostRequestGetLocationLastRequestPath = requestPath;
			PostRequestGetLocationLastData = data;
			return PostRequestGetLocationFakeResult;
		}
		public bool PostRequestGetLocationCalled { get; private set; }
		public string PostRequestGetLocationLastRequestPath { get; private set; }
		public string PostRequestGetLocationLastData { get; private set; }
		public string PostRequestGetLocationFakeResult { private get; set; }

		public string PutRequest(string requestPath, string data)
		{
			PutRequestCalled = true;
			PutRequestLastRequestPath = requestPath;
			return PutRequestFakeResult;
		}
		public bool PutRequestCalled { get; private set; }
		public string PutRequestLastRequestPath { get; private set; }
		public string PutRequestFakeResult { private get; set; }

		public string DeleteRequest(string requestPath)
		{
			DeleteRequestCalled = true;
			DeleteRequestLastRequestPath = requestPath;
			return DeleteRequestFakeResult;
		}
		public bool DeleteRequestCalled { get; private set; }
		public string DeleteRequestLastRequestPath { get; private set; }
		public string DeleteRequestFakeResult { private get; set; }
	}
}